package com.lhz.controller;

import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.lhz.services.ArrangeTableService;

@Controller
@RequestMapping("/appoint")//预约
public class ArrangeTableControll {
	/*appointmentshow?pgeNow=1&pageSize=10*/
	
	/**
	 *                 _ooOoo_
	 *                o8888888o
	 *                88" . "88
	 *                (| -_- |)
	 *                O\  =  /O
	 *             ____/`---'\____
	 *           .'  \\|     |//  `.
	 *          /  \\|||  :  |||//  \
	 *         /  _||||| -:- |||||-  \
	 *         |   | \\\  -  /// |   |
	 *         | \_|  ''\---/''  |   |
	 *         \  .-\__  `-`  ___/-. /
	 *       ___`. .'  /--.--\  `. . __
	 *    ."" '<  `.___\_<|>_/___.'  >'"".
	 *   | | :  `- \`.;`\ _ /`;.`/ - ` : | |
	 *   \  \ `-.   \_ __\ /__ _/   .-` /  /
	 *====`-.____`-.___\_____/___.-`____.-'======
	 *                 `=---='
	 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
	 *             佛祖保佑       永无BUG
	 */
	
	
	@Autowired
	private ArrangeTableService service;
	
	
	/**
	 * 显示预约界面所有信息
	 * @return
	 */
	@RequestMapping(value="/appointmentshow")
	public ModelAndView arrangeTableshow(
			@RequestParam(name="pageNow",defaultValue="1")int pageNow,
			@RequestParam(name="pageSize",defaultValue="10")int pageSize,
			String number,
			String phone,
			String startTime) {
		ModelAndView mv=new ModelAndView();
		try {
			if(number!=null||phone!=null) {
				Map<String, Object> info = service.searchByArrangeTable(pageNow,pageSize,number,phone,startTime);
				if(!info.isEmpty()) {
					ModelAndView a = mv.addObject("map", info);
					if(!a.isEmpty()) {
						mv.setViewName("ArrangeTable");
					}else {
						mv.setViewName("message");
					}
					return mv;
				}
			}
			Map<String, Object> info = service.searchByArrangeTable(pageNow,pageSize);
			if(!info.isEmpty()) {
				mv.addObject("map", info);
				mv.setViewName("ArrangeTable");
				return mv;
			}else {
				mv.setViewName("message");
			}
		} catch (Exception e) {
			throw new RuntimeException("在35行报错啦!。。。。。");
		}
		return mv;
	}
	/**
	 * 制定用户进行排队
	 * @param aptId
	 * @param renshu
	 * @return
	 */
	@RequestMapping(value="/updateStatsArrangeTable")
	@ResponseBody
	public Map<String,Object> updateStatsArrangeTable(Integer aptId,Integer renshu){
		try {
			return service.updateStatsArrangeTable(aptId,renshu);
		} catch (Exception e) {
			throw new RuntimeException("指定用户排队出错啦!....在69行");
		}
		
	}
	
	
	
}
